File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 31
31
def get_flagged_objects (reason = None , exclude_reason = None , content_model = None , product_slug = None ):
32
32
"""Retrieve pending flagged objects with optional filtering, eager loading related fields."""
33
33
queryset = FlaggedObject .objects .pending ().select_related ("content_type" , "creator" )
34
+
34
35
if exclude_reason :
35
36
queryset = queryset .exclude (reason = exclude_reason )
36
37
if reason :
37
38
queryset = queryset .filter (reason = reason )
38
39
if content_model :
39
40
queryset = queryset .filter (content_type = content_model )
40
- if product_slug :
41
- matching_product_ids = [
42
- obj .id
43
- for obj in queryset
44
- if hasattr (obj .content_object , "product" )
45
- and obj .content_object .product .slug == product_slug
46
- ]
47
- queryset = queryset .filter (id__in = matching_product_ids )
41
+
42
+ if product_slug :
43
+ model_class = content_model .model_class ()
44
+
45
+ if hasattr (model_class , "product" ):
46
+ matching_objects = model_class .objects .filter (product__slug = product_slug )
47
+ matching_ids = matching_objects .values_list ("id" , flat = True )
48
+
49
+ queryset = queryset .filter (object_id__in = matching_ids )
50
+
48
51
return queryset
49
52
50
53
You can’t perform that action at this time.
0 commit comments